Skip to main content

Compact Monthly Vendor Activity Table Documentation

This project explores efficient data modeling and compression techniques for NYC Yellow Taxi trip data using PySpark on Microsoft Fabric. The goal is to reduce storage footprint and improve query performance while maintaining the ability to conduct granular day-level analysis. Code Repo:

Overview: What the Code Does

The notebook ingests raw yellow_tripdata, aggregates it at a daily level, and then compresses it into a monthly-level fact table where each vendor has one row per month. Within this row, daily values (e.g., trip counts, fares, tips) are stored in arrays, ordered using a reverse-day index (e.g., 31st = 0, 30th = 1, etc.).

Full Code Workflow (Step-by-Step)

Step 1: Load Raw Data

Description: Reads the full NYC Taxi trip data table from Microsoft Fabric Lakehouse. Displays the first 50 rows for inspection.

Step 2: Create Date Columns

Description: Adds helper columns to enable time-based aggregation. reverse_day_index allows the final arrays to be reverse-ordered.

Step 3: Aggregate Daily Activity

Description: Aggregates daily taxi activity per vendor by month and reverse day index. Sample Output:

Step 4: Ensure All Days Are Present

Description: Builds a full calendar grid for each vendor and month, even if some days had no activity. Sample Output: Includes NULLs for days with no trips.

Step 5: Prepare Data for Compression

Description: Handles missing/null values and ensures uniform schema for all array metrics.

Step 6: Build Compact Fact Table with Arrays

Description: Compresses daily metrics into reverse-ordered arrays.

Step 7: Save Table

Description: Saves the final compact fact table to the Lakehouse.

Step 8: Explode and Validate

Description: Converts the monthly arrays back into row-level records for verification, visual inspection, or further analysis.

Comparison with Other Tables

Print Sizes & Counts

Benefits of This Approach

  • Storage Efficiency: Reduces rows by 30× per vendor/month, storing daily metrics in arrays.
  • Query Performance: Smaller fact table means faster scans and joins .
  • Flexibility: Arrays can be exploded back to day‑level for anomaly detection or trend analysis.
  • Reduced Shuffling: Minimal data movement when joining with dimension tables (e.g., dim_vendor).

Real-World Use Cases

1. NYC Taxi Vendor Activity

  • Traditional Daily Model: 2 vendors × 30 days = 60 rows per month
  • Compact Model: 2 rows per month
  • Gain: 30× row reduction, less storage, faster dashboards.

2. IoT Device Telemetry (Hypothetical)

  • Daily Records: 10 M devices × 30 days = 300 M rows/month
  • Compact Model: 10 M rows/month with arrays of daily metrics
  • Gain: 30× reduction, enabling scalable time-series analytics.

3. Web Analytics Summary

  • Summarize daily user sessions or event counts per site/per month into arrays for quick monthly overviews and drill‑downs.